const username =document.querySelector('#username')
const pwd=document.querySelector('#password')
const btn = document.querySelector('.btn')
const checkbox = document.querySelector('#check')

btn.onclick=function (){
    if (checkbox.checked==false)
    {
        alert("勾选用户协议")
    }
    else
    {
        const xhr = new XMLHttpRequest()
        xhr.open('POST','http://8.130.14.155:8080/user/login','true')
        xhr.setRequestHeader('Content-Type','application/json')
        const params={
            username:username.value,
            password:pwd.value,
        }
        var name=username.value
        xhr.send(JSON.stringify(params))
        xhr.onreadystatechange=function (){

            if(xhr.readyState===4&&xhr.status===200){

                var result=JSON.parse(xhr.responseText)
                console.log(result)
                if (result.msg=='操作成功')
                {
                    alert("登陆成功！")
                    localStorage.setItem("username",username.value)
                    location.href='index.html'
                }
                else {
                    alert(result.msg)
                    window.location.href="login.html"
                }
            }

        }
    }
}
